package com.jingzhi.count.controller;

import com.jingzhi.count.entity.MyResponse;
import com.jingzhi.count.entity.Product;
import com.jingzhi.count.mapper.ProductMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 作者： 张恒同
 * 时间： 2018/3/29   09:45
 * 描述： 产品
 */
@RestController
@RequestMapping("/products")
public class ProductController extends BaseController{

    @Autowired
    private ProductMapper   mapper;

    @PostMapping(value = "/addProduct.do")
    public ResponseEntity<MyResponse> addProduct(@RequestParam(value = "name", required = true, defaultValue = "0") String name, @RequestParam(value = "alochol", required = true, defaultValue = "0") String alochol){
        MyResponse  response = new MyResponse();

        logger.info("name - " + name);

        Product product = new Product();
        product.setName(name);
        product.setAlcohol(alochol);
        mapper.insert(product);

        response.setRc(0);
        response.setDes("商品添加成功");

        return new ResponseEntity<MyResponse>(response, HttpStatus.OK);
    }


}
